package com.lanou.moving.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lanou.moving.R;
import com.lanou.moving.activity.MainActivity;
import com.lanou.moving.adapter.MVAreaAdapter;
import com.lanou.moving.base.BaseFragment;

/**
 * Created by 梁树珍 on 15/11/3.
 */
public class MVAreaFragment extends BaseFragment implements View.OnClickListener {
    private ViewPager mv_area_viewpager;
    private TabLayout mv_area_tablayout;
    private MVAreaAdapter adapter;
    private ImageView mv_area_back;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.i("Sysout","MV->onCreateView");
        View view = inflater.inflate(R.layout.fragment_mv_area, null);
        mv_area_viewpager = (ViewPager) view.findViewById(R.id.mv_area_viewpager);
        mv_area_tablayout = (TabLayout) view.findViewById(R.id.mv_area_tablayout);
        mv_area_back = (ImageView) view.findViewById(R.id.mv_area_back);
        mv_area_back.setOnClickListener(this);
        init();
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        init();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("Sysout","MV->onDestroy");
    }

    private void init(){
        adapter = new MVAreaAdapter(getFragmentManager());
        mv_area_viewpager.setAdapter(adapter);
        mv_area_tablayout.setupWithViewPager(mv_area_viewpager);
        mv_area_tablayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.resideMenu_bg));
        mv_area_tablayout.setTabTextColors(getResources().getColor(R.color.cardview_dark_background)
        , getResources().getColor(R.color.resideMenu_bg));
    }

    @Override
    public void onClick(View v) {
//        ((MainActivity)getActivity()).killMvFragment();
        getFragmentManager().popBackStack();
        adapter.killAllFragments();
    }
}
